using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using DragonAwakening.Core.Game;

namespace DragonAwakening.Core.Game
{
    /// <summary>
    /// Character sex
    /// </summary>
    public enum Sex
    { 
        Male,
        Female
    }

    /// <summary>
    /// Character class
    /// </summary>
    public enum CharacterClass
    {
        Barbarian,
        Bard,
        Cleric,
        Druid,
        Fighter,
        Monk,
        Paladin,
        Ranger,
        Rogue,
        Sorcerer,
        Wizard
    }

    /// <summary>
    /// Character game.
    /// </summary>
    public class Character : CombatCreature
    {
        /// <summary>
        /// Creates character.
        /// </summary>
        /// <param name="race"></param>
        public Character(string name, RaceName race, CharacterClass characterClass, Sex sex)
        {
            this.Race = new Race(race);
            this.Name = name;
            this.Class = characterClass;
            this.Sex = sex;

            this.Health = new MaxValueData() { Max = 100, Current = 80 };
            this.Stamina = new MaxValueData() { Max = 100, Current = 100 };
            this.Mana = new MaxValueData() { Max = 100, Current = 10 };
            
            this.IsAlive = true;
            this.ArmorClass = new MaxValueData() { Max = 16, Current = 16 };
            this.Level = 1;

            this.Strength = new MaxValueData() { Max = 8, Current = 8 };
            this.Intellect = new MaxValueData() { Max = 10, Current = 6 };
            this.Dexterity = new MaxValueData() { Max = 8, Current = 16 };
        }

        #region - Base properties -

        /// <summary>
        /// Gets the character race.
        /// </summary>
        public Race Race { get; private set; }

        /// <summary>
        /// Gets the character class.
        /// </summary>
        public CharacterClass Class { get; private set; }

        /// <summary>
        /// Character sex
        /// </summary>
        public Sex Sex { get; private set; }

        /// <summary>
        /// Gets the character level.
        /// </summary>
        public int Level { get; private set; }

        /// <summary>
        /// Name
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Health points
        /// </summary>
        public MaxValueData Health { get; private set; }

        /// <summary>
        /// Stamina
        /// </summary>
        public MaxValueData Stamina { get; private set; }

        /// <summary>
        /// Mana/Power pool
        /// </summary>
        public MaxValueData Mana { get; private set; }

        #endregion - Base properties -

        #region - Main attributes -

        /// <summary>
        /// Vitality
        /// </summary>
        public MaxValueData Vitality { get; private set; }

        /// <summary>
        /// Strength
        /// </summary>
        public MaxValueData Strength { get; private set; }

        /// <summary>
        /// Dexterity
        /// </summary>
        public MaxValueData Dexterity { get; private set; }

        /// <summary>
        /// Intellect
        /// </summary>
        public MaxValueData Intellect { get; private set; }

        /// <summary>
        /// Spirit
        /// </summary>
        public MaxValueData Spirit { get; private set; }

        /// <summary>
        /// Armor class
        /// </summary>
        public MaxValueData ArmorClass { get; private set; }

        /// <summary>
        /// Block chance
        /// </summary>
        public MaxValueData Block { get; private set; }

        /// <summary>
        /// Dodge chance
        /// </summary>
        public MaxValueData Dodge { get; private set; }

        /// <summary>
        /// Miss chance
        /// </summary>
        public MaxValueData Miss { get; private set; }

        /// <summary>
        /// Critical hit chance
        /// </summary>
        public MaxValueData Critical { get; private set; }

        /// <summary>
        /// Current level experience
        /// </summary>
        public MaxValueData Experience { get; private set; }

        /// <summary>
        /// Max carry
        /// </summary>
        public MaxValueData Carry { get; private set; }

        /// <summary>
        /// Melee / spell power modifier
        /// </summary>
        public MaxValueData Power { get; private set; }

        #endregion - Main attributes -

        public bool IsAlive;

        public void TakeDamage(int damage, IGameContext game, List<KeyValuePair<string, float>> messages)
        {
            var health = this.Health;
            health.Current = Math.Max(0, this.Health.Current - damage);
            if (health.Current == 0)
            {
                this.IsAlive = false;
            }
            this.Health = health;
        }
    }
}
